#include "stdafx.h"
#include <list>
#include <string>
#include "FEngineType.h"
#include "GUINode.h"

using namespace std;

namespace FEngine
{
	GUINode::GUINode()
	{
		mParentNode		= NULL;
		mPosition		= Vector2(0.0f, 0.0f);
	}

	GUINode::~GUINode()
	{
		if (mParentNode != NULL)
			mParentNode->removeChild(this);

		for (list<GUINode*>::iterator it = mChildNodeList.begin(); it != mChildNodeList.end(); ++it)
			(*it)->_setParentNode(NULL);
	}
	
	void GUINode::addChild(GUINode* _node)
	{
		if (_node == this)
			return;

		mChildNodeList.push_back(_node);
		_node->_setParentNode(this);
	}
	
	void GUINode::removeChild(GUINode* _node)
	{
		mChildNodeList.remove(_node);
		_node->_setParentNode(NULL);
	}

	void GUINode::_setParentNode(GUINode* _node)
	{
		mParentNode = _node;
	}
	
	void GUINode::setPosition(const Vector2& _pos)
	{
		mPosition = _pos;
	}

	void GUINode::setPosition(float _x, float _y)
	{
		mPosition.x = _x;
		mPosition.y = _y;
	}
	
	void GUINode::translate(const Vector2& _pos)
	{
		mPosition += _pos;
	}

	void GUINode::translate(float _x, float _y)
	{
		mPosition.x += _x;
		mPosition.y += _y;
	}

	void GUINode::update(double _elapsedTime)
	{
		for (list<GUINode*>::iterator it = mChildNodeList.begin(); it != mChildNodeList.end(); ++it)
			(*it)->update(_elapsedTime);
	}

	void GUINode::render(double _elapsedTime)
	{
		for (list<GUINode*>::iterator it = mChildNodeList.begin(); it != mChildNodeList.end(); ++it)
			(*it)->render(_elapsedTime);
	}

} // namespace FEngine
